package com.ruoyi.web.controller.tool;


import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class ShortLinkUtil {


    private static final String CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";


    public static String generateUniqueRandomString(int length) {
        Set<String> generatedStrings = new HashSet<>();
        String randomString;
        randomString = generateRandomString(length);
        generatedStrings.add(randomString);
        return randomString;
    }

    public static String generateRandomString(int length) {
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(CHARACTERS.length());
            char randomChar = CHARACTERS.charAt(index);
            sb.append(randomChar);
        }
        return sb.toString();
    }

}
